package com.biqee.framework.spring;

import java.util.Collection;
import java.util.Map;

import javax.servlet.ServletContextEvent;

import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

public class BqContextLoaderListener extends ContextLoaderListener {



	/**
	 * Initialize the root web application context.
	 */
	public void contextInitialized(ServletContextEvent event) {
		this.initWebApplicationContext(event.getServletContext());
		doAfer(ContextLoader.getCurrentWebApplicationContext());
	}

	private void doAfer(WebApplicationContext currentWebApplicationContext) {
		Map<String, OnConextFinishedListener> onFinishBeans = currentWebApplicationContext
				.getBeansOfType(OnConextFinishedListener.class);
		if (onFinishBeans != null) {
			Collection<OnConextFinishedListener> events = onFinishBeans.values();
			for (OnConextFinishedListener event : events) {
				event.execute();
			}
		}

	}

}
